﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Microhard.Core;
using Microhard.Framework.MVCHelper;

namespace Microhard.Framework.Extensions
{
    public static class HttpExtensions
    {
        /// <summary>
        /// 是否是从微信的手机浏览器中发出的请求
        /// </summary>
        /// <param name="filterContext"></param>
        /// <returns></returns>
        public static bool IsWeixinClientRequest(this HttpContextBase httpContext)
        {
            var request = httpContext.Request;
            //  Log.Info("MicroMessenger", "BrowserType:" + request.Browser.Type + " UserAgent:" + request.UserAgent
            //+ " MobileDeviceModel:" + request.Browser.MobileDeviceModel + " MobileDeviceManufacturer:" + request.Browser.MobileDeviceManufacturer
            //+ " ScreenPixelsWidth" + request.Browser.ScreenPixelsWidth + " ScreenPixelsHeight" + request.Browser.ScreenPixelsHeight);

            if (!string.IsNullOrEmpty(request.UserAgent) &&
                   (request.UserAgent.Contains("MicroMessenger") || request.UserAgent.Contains("IEMobile")))
            {
                if (!httpContext.Items.Contains(SysConst.ISMOBILERQUEST))
                {
                    httpContext.Items.Add(SysConst.ISMOBILERQUEST, true);
                }
                return true;
            }
            return false;
        }

        /// <summary>
        /// 是否是支持的手机版本
        /// </summary>
        /// <param name="httpContext"></param>
        /// <returns></returns>
        public static bool IsSuitableMobile(this HttpContextBase httpContext)
        {
            var request = httpContext.Request;
            return request.Browser.IsMobileDevice;
            //return true;
        }
    }
}
